require 'cgi/session'
require 'account/account_helper'

#
# === ToDo Dash コントローラ
#
# Note:: 各ページに必要な処理を定義する．
# Author:: krdlab
#
class ToDoDashController

	def initialize
		@cgi = CGI.new
		@session = CGI::Session.new(@cgi)
	end

	def redirect_to(path)
		@cgi.header({'status' => "302 Found", 'Location' => path})
	end

	def request_is_POST?
		@cgi.request_method.upcase == "POST"
	end

	def try_login
		helper = create_helper
		ret = helper.login
		update_session
		return ret
	end

	def try_logout
		helper = create_helper
		ret = helper.logout
		delete_session
		return ret
	end

	def new_account
		helper = create_helper
		ret = helper.new_account
		update_session
		return ret
	end

	def get_account
		helper = create_helper
		ret = helper.get_account
		update_session
		return ret
	end

	def update_session
		@session.close
		@cgi.header
	end

	def delete_session
		@session.delete
		@cgi.header
	end

	def get_parameter(name)
		return @cgi[name]
	end

private
	def create_helper
		AccountHelper.new(@cgi, @session)
	end
end

